package logic

import (
	"context"
	"work-safety/models/mysql"

	"work-safety/workrpc/internal/svc"
	"work-safety/workrpc/workrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *workrpc.AddRequest) (*workrpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	data := mysql.Author{

		Name:   in.Name,
		Price:  in.Price,
		Image:  in.Image,
		UserId: in.UserId,
	}
	mysql.DB.Debug().Create(&data)
	return &workrpc.AddResponse{
		AuthorId: int64(data.ID),
	}, nil
}
